package edu.gatech.asthma.ui_support;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

import edu.gatech.asthma.R;
import android.annotation.SuppressLint;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.support.v4.app.DialogFragment;
import android.os.Bundle;
import android.widget.DatePicker;
import android.widget.RadioButton;

/**
 * Fragment for the date picker
 */
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
	// Use the current date as the default date in the picker
	final Calendar c = Calendar.getInstance();
	int year = c.get(Calendar.YEAR);
	int month = c.get(Calendar.MONTH);
	int day = c.get(Calendar.DAY_OF_MONTH);
	
	// Create a new instance of DatePickerDialog and return it
	return new DatePickerDialog(getActivity(), this, year, month, day);
	}
	
	@SuppressLint("SimpleDateFormat")
	public void onDateSet(DatePicker view, int year, int month, int day) {
	// Do something with the date chosen by the user
		RadioButton past = (RadioButton) getActivity().findViewById(R.id.symptoms_time_past);
		//note month's index starts at 0 for January
		Calendar cal = new GregorianCalendar(year, month, day);
		String date = new SimpleDateFormat("MM-dd-yyyy").format(cal.getTime());
		String text = getActivity().getString(R.string.symptoms_previously) + " (" + date + ")";
		past.setText(text);
	}
}
